package com.example.sunmiv1.vm

import com.example.sunmiv1.activity.CollectRecordActivity
import com.example.sunmiv1.adapter.CollectRecordAdapter
import com.example.sunmiv1.room.OrderManager
import com.example.sunmiv1.room.entity.OrderEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class CollectRecordViewModel(private val mActivity:CollectRecordActivity){
    private val mList= arrayListOf<OrderEntity>()
    fun init(adapter: CollectRecordAdapter){
        GlobalScope.launch(Dispatchers.IO){
            val list=OrderManager.getAll()
            mList.clear()
            mList.addAll(list)
            GlobalScope.launch(Dispatchers.Main){
                adapter.setOrderList(mList)
            }
        }
    }
}